Use case: Arbitrary waveform generation ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|
|---|---|---|
|
Usage |
HRTIM_HandleTypeDef hhrtim;
HRTIM_TimeBaseCfgTypeDef sConfig_time_base;
HRTIM_TimerCfgTypeDef sConfig_timerD;
HRTIM_OutputCfgTypeDef sConfig_output_config;
HRTIM_CompareCfgTypeDef sConfig_compare;
hhrtim1.Instance = HRTIM1;
hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
HAL_HRTIM_Init(&hhrtim);
/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
.................
................
sConfig_time_base.Period = 0x2000;
sConfig_time_base.RepetitionCounter = 0x00;
sConfig_time_base.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV4;
sConfig_time_base.Mode = HRTIM_MODE_CONTINUOUS;
HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_time_base);
sConfig_timerD.InterruptRequests = HRTIM_MASTER_IT_NONE;
sConfig_timerD.DMARequests = HRTIM_MASTER_DMA_NONE;
sConfig_timerD.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
sConfig_timerD.InterleavedMode = HRTIM_INTERLEAVED_MODE_DISABLED;
sConfig_timerD.StartOnSync = HRTIM_SYNCSTART_DISABLED;
sConfig_timerD.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
sConfig_timerD.DACSynchro = HRTIM_DACSYNC_NONE;
sConfig_timerD.PreloadEnable = HRTIM_PRELOAD_ENABLED;
sConfig_timerD.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
sConfig_timerD.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
sConfig_timerD.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
sConfig_timerD.ReSyncUpdate = HRTIM_TIMERESYNC_UPDATE_UNCONDITIONAL;
HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_timerD);
/* Set compare register 1 in Timer D */
sConfig_compare.CompareValue = 0x10;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_1, &sConfig_compare);
/* Set compare register 2 in Timer D */
sConfig_compare.CompareValue = 0x20;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_2, &sConfig_compare);
/* Set compare register 3 in Timer D */
sConfig_compare.CompareValue = 0x30;
HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_3, &sConfig_compare);
sConfig_output_config.Polarity = HRTIM_OUTPUTPOLARITY_HIGH;
sConfig_output_config.IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
sConfig_output_config.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
sConfig_output_config.SetSource = HRTIM_OUTPUTSET_TIMPER | HRTIM_OUTPUTSET_TIMCMP1 | HRTIM_OUTPUTSET_TIMCMP2 ;
sConfig_output_config.ResetSource = HRTIM_OUTPUTRESET_TIMPER | HRTIM_OUTPUTRESET_TIMCMP1 | HRTIM_OUTPUTRESET_TIMCMP2;
HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, &sConfig_output_config);
sConfig_output_config.SetSource = HRTIM_OUTPUTSET_TIMPER | HRTIM_OUTPUTSET_TIMCMP2 ;
sConfig_output_config.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1 | HRTIM_OUTPUTRESET_TIMCMP2;
HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD2, &sConfig_output_config);
/* Enable HRTIM's outputs TD1 and TD2 */
HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD1 | HRTIM_OUTPUT_TD2);
/* Start HRTIM TIMER D in polling mode*/
HAL_HRTIM_WaveformCountStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D);
|
hal_hrtim_handle_t hhrtim;
hal_hrtim_timer_config_t timer_d_config;
hal_hrtim_output_config_t output_config;
HAL_HRTIM_Init(&hhrtim1, HAL_HRTIM1);
/* Enable peripherals: HRTIM and GPIO Clocks, configure GPIO Pin*/
.................
................
timer_d_config.period = 0x2000;
timer_d_config.repetition = 0x00;
timer_d_config.prescaler = HAL_HRTIM_TIM_PRESCALER_DIV4;
timer_d_config.operating_mode = HAL_HRTIM_TIM_MODE_CONTINUOUS;
HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMD, &timer_d_config);
HAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_UPDATE_SOURCE_REPETITION);
HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMD);
/* Set compare register 1 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_1, 0x10);
/* Set compare register 2 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_2, 0x20);
/* Set compare register 3 in Timer D */
HAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_3, 0x30);
output_config.set = HAL_HRTIM_OUT_SET_PERIOD | HAL_HRTIM_OUT_SET_CMP1 | HAL_HRTIM_OUT_SET_CMP2;
output_config.reset = HAL_HRTIM_OUT_RESET_PERIOD | HAL_HRTIM_OUT_RESET_CMP1 | HAL_HRTIM_OUT_RESET_CMP2;
output_config.polarity = HAL_HRTIM_OUTPUT_ACTIVE_HIGH;
output_config.idle_level = HAL_HRTIM_OUTPUT_IDLE_INACTIVE;
output_config.fault_level = HAL_HRTIM_OUTPUT_FAULT_NONE;
HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD1, &output_config);
output_config.set = HAL_HRTIM_OUT_SET_PERIOD |HAL_HRTIM_OUT_SET_CMP2;
output_config.reset = HAL_HRTIM_OUT_RESET_CMP1 | HAL_HRTIM_OUT_RESET_CMP2;
HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD2, &output_config);
/* Enable HRTIM's outputs CHD1 and CHD2 */
HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHD1 | HAL_HRTIM_CHD2));
/* Start HRTIM's TIMER D in polling mode */
HAL_HRTIM_TIM_Start(&hhrtim, HAL_HRTIM_TIMD);
|
Key changes ¶
HAL2 uses
HAL_HRTIM_TIM_SetConfig()with default values for non-configured fields.HAL2 sets compare values via
HAL_HRTIM_TIM_SetCompareValue()instead of waveform compare configuration.HAL2 splits output configuration (
HAL_HRTIM_OUT_SetConfig()) from output enabling (HAL_HRTIM_OUT_Enable()) and timer start (HAL_HRTIM_TIM_Start()).
![@startuml
participant "User Application" as App
participant "HAL HRTIM" as Driver
group HRTIM Initialization
App -[hidden]>Driver
end
group Timer D configuration
App->Driver : HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, &sConfig_time_base);
Driver --> App : HAL_OK
App->Driver : \nHAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D,&sConfig_timerD);
Driver --> App : HAL_OK
App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_1, &sConfig_compare);
Driver --> App : HAL_OK
App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_2, &sConfig_compare);
Driver --> App : HAL_OK
App->Driver : \n HAL_HRTIM_WaveformCompareConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_COMPAREUNIT_3, &sConfig_compare);
Driver --> App : HAL_OK
App->Driver : HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, &sConfig_output_config)
Driver --> App : HAL_OK
App->Driver : HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD2, &sConfig_output_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.
end
group Start Signal generation
App -> Driver : HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, (HRTIM_OUTPUT_TD1 | HRTIM_OUTPUT_TD2))
Driver --> App : HAL_OK
App -> Driver : HAL_HRTIM_WaveformCountStart(&hhrtim, HRTIM_TIMERINDEX_TIMER_D)
Driver --> App : HAL_OK
end
@enduml](../../../../../_images/plantuml-93b356eebec718760b9d341ea39b9ddfdb8f8724.png)
![@startuml
' To add a number by line
'autonumber
' Fix order of each column
participant "User Application" as App
participant "HAL HRTIM" as Driver
group HRTIM Initialization
App -[hidden]>Driver
end
group Timer D configuration
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMD, &timer_d_config)
Driver --> App : HAL_OK
App->Driver : \nHAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_UPDATE_EVENT_REPETITION)
Driver --> App : HAL_OK
App -> Driver : HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMD)
Driver --> App : HAL_OK
App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_1, 0x10)
Driver --> App : HAL_OK
App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_2, 0x20)
Driver --> App : HAL_OK
App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_3, 0x30)
Driver --> App : HAL_OK
App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD1, output_config)
Driver --> App : HAL_OK
App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD2, output_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.
end
group Start Signal generation
App -> Driver : HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHD1 | HAL_HRTIM_CHD2))
Driver --> App : HAL_OK
App -> Driver : HAL_HRTIM_TIM_Start(&hhrtim, HAL_HRTIM_TIMD)
Driver --> App : HAL_OK
end
@enduml](../../../../../_images/plantuml-54f5586cb931a70ab54cc86573e83e70629d3787.png)